/**
 * Created by Administrator on 2017/2/17.
 */
import { Component } from '@angular/core';
import { gamePreviewService } from '../../service/gamePreview.service';
import { Router, ActivatedRoute, Params } from '@angular/router';
import 'rxjs/add/operator/switchMap';
declare let $:any;
declare let jQuery:any;
declare let Clipboard:any;
@Component({
    selector: 'game_view',
    templateUrl: '../../../views/game_view/gameView.html',
    styleUrls: ['../../../css/game_view/gameView.css'],
    providers: [
        gamePreviewService
    ]
})
export class GameViewComponent {
    public gid:any;
    public name:any;
    public resource:any;
    public resource_url:any;
    public url_game:any;
    constructor(
        private router : Router,
        private route: ActivatedRoute,
        private gamePreview : gamePreviewService
    ){
        let self : any = this;
        console.log( self.route.params);
        self.gid = self.route.params.value.id;
        self.showGamePreview();
    }
    //展示游戏
    public showGamePreview(){
        let self:any = this;
        let data:any = {
            id : self.gid
        };
        self.gamePreview.getGamePreview({
            data : data,
            success : function (result:any) {
                console.log(result.resource_url);
                self.name = result.data.name;
                self.resource = result.data.resource;
                self.resource_url = result.resource_url;
                self.url_game=  self.resource_url + self.resource + "index.html";
                $("#game").attr("src",self.url_game);
                jQuery('#output').qrcode({
                    width : 140,
                    height :140,
                    text : self.url_game
                });
            }
        })
    }
    //复制文本内容到剪贴板
    public copyGameUrl(){
        var clipboard = new Clipboard('#btn-copy', {
            text: function() {
                return this.url_game;
            }
        });
    }
}
